package com.fowo.api.syncAmazon.entity;

import com.amazon.spapi.model.listingsitems.ItemSummaryByMarketplace;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import java.io.Serializable;
import java.time.Instant;
import java.time.LocalDateTime;
import java.util.Date;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import org.threeten.bp.OffsetDateTime;


/**
 * @TableName amazon_listing_summaries
 */
@TableName(value ="amazon_listing_summaries",autoResultMap = true)
@Data
public class AmazonListingSummaries implements Serializable {
    @TableField(value = "`id`")
    @TableId(type = IdType.ASSIGN_ID)
    @Schema(title = "编号")
    private Long id;

    private String sku;

    private String marketplaceid;

    private String asin;

    private String producttype;

    private String conditiontype;

    private String status;

    private String fnsku;

    private String itemname;

    private LocalDateTime createddate;

    private LocalDateTime lastupdateddate;

    private String mainimage;

    private static final long serialVersionUID = 1L;

    public void copy(ItemSummaryByMarketplace itemSummaryByMarketplace,String sku){
        this.marketplaceid = itemSummaryByMarketplace.getMarketplaceId();
        this.asin = itemSummaryByMarketplace.getAsin();
        this.sku = sku;
        this.producttype = itemSummaryByMarketplace.getProductType();
        this.conditiontype =itemSummaryByMarketplace.getConditionType().getValue() != null ? itemSummaryByMarketplace.getConditionType().getValue() : null;
        StringBuilder stringBuilder = new StringBuilder();
        for (ItemSummaryByMarketplace.StatusEnum status : itemSummaryByMarketplace.getStatus()) {
            stringBuilder.append(status.getValue());
            stringBuilder.append(",");
        }
        this.status = stringBuilder.toString();
        this.fnsku = itemSummaryByMarketplace.getFnSku() != null ? itemSummaryByMarketplace.getFnSku() : null;
        this.itemname = itemSummaryByMarketplace.getItemName();
        this.createddate = convert(itemSummaryByMarketplace.getCreatedDate());
        this.lastupdateddate = convert(itemSummaryByMarketplace.getLastUpdatedDate());
        this.mainimage = itemSummaryByMarketplace.getMainImage() != null ? itemSummaryByMarketplace.getMainImage().getLink() : null;
    }
    private LocalDateTime convert(OffsetDateTime offsetDateTime){
        java.time.OffsetDateTime odt = java.time.OffsetDateTime.parse(offsetDateTime.toString());

        // 再将 Instant 转换为 Date
        return odt.toLocalDateTime();
    }
}